package cn.school.controller.hotel;


import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.hotel.entity.TripAreaDic;
import cn.school.hotel.entity.TripHotel;
import cn.school.hotel.entity.TripHotelRoom;
import cn.school.hotel.service.HotelManageService;
import cn.school.hotel.service.TripAreaDicService;
import cn.school.hotel.vo.ItripHotelRoomVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "Hotel-Manage => 酒店管理")
@RequestMapping("/hotel/hotelManage")
public class HotelManageController {

    @Autowired
    private HotelManageService hotelManageService;

    @Autowired
    private TripAreaDicService tripAreaDicService;

    @ApiOperation("list => 分页查询酒店列表")
    @GetMapping(value = "/getHotelPagelist")
    public CommonResult<CommonPage<TripHotel>> getHotelPagelist(TripHotel tripHotel,
                                                                      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        IPage<TripHotel> page = hotelManageService.getHotelPagelist(tripHotel,pageSize,pageNum);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("getHoteInfoDetail => 查询酒店详情")
    @GetMapping(value = "/getHoteInfoDetail")
    public CommonResult<TripHotel> getHoteInfoDetail(@RequestParam("id")String id) {
        TripHotel tripHotel = hotelManageService.getHotelInfoDetail(id);
        return CommonResult.success(tripHotel,"成功");
    }

    @ApiOperation("createHoteInfo => 新建酒店信息")
    @PostMapping(value = "/createHoteInfo")
    public CommonResult<CommonPage<TripHotel>> createHoteInfo(@RequestBody  TripHotel tripHotel) {
        int page = hotelManageService.createHoteInfo(tripHotel);
        if(page > 0 ){
           return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteHoteInfo => 删除酒店信息")
    @GetMapping(value = "/deleteHoteInfo")
    public CommonResult<Integer> deleteHoteInfo(@RequestParam("id")String id) {
        int count = hotelManageService.deleteHoteInfo(id);
        if(count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();

    }

    @ApiOperation("getAreaList => 根据PID获取区域信息")
    @GetMapping(value = "/getAreaList")
    public CommonResult<List<TripAreaDic>> getAreaList(@RequestParam("pid")String id){
        List<TripAreaDic> areaList = tripAreaDicService.getArealist(id);
        return CommonResult.success(areaList,"成功");
    }

    @ApiOperation("getAreaList => 根据hotelID获取房间信息")
    @GetMapping(value = "/getHotelRoomList")
    public CommonResult<List<ItripHotelRoomVO>> getHotelRoomList(@RequestParam("hotelId")String id){
        List<ItripHotelRoomVO> roomList = hotelManageService.getHotelRoomList(id);
        return CommonResult.success(roomList,"成功");
    }

    @ApiOperation("getAreaList => 根据hotelID获取房间信息")
    @PostMapping(value = "/createOrUpdateHotelRoom")
    public CommonResult<List<TripHotelRoom>> createOrUpdateHotelRoom(@RequestBody  List<TripHotelRoom> roomList){
        int count = hotelManageService.createOrUpdateHotelRoom(roomList);
        if(count>0){
            return CommonResult.success(roomList,"成功");
        }
        return CommonResult.failed();
    }


}
